# 指定 CMake 最低版本
cmake_minimum_required(VERSION 2.8)

# 定义项目名称
project(TEST_INIT)

# 设置默认的构建类型为 Debug（如果未指定）
IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE Debug) # 默认设置为 Debug 模式
ENDIF()

# 设置编译选项，确保禁用优化并启用调试信息
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -g -O0 -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -g -O0 -march=native")

# 检查 C++11 或 C++0x 支持
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
   add_definitions(-DCOMPILEDWITHC11)
   message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
   add_definitions(-DCOMPILEDWITHC0X)
   message(STATUS "Using flag -std=c++0x.")
else()
   message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

# 添加自定义模块路径（如果有额外的 CMake 模块）
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

# 查找 OpenCV 库
find_package(OpenCV REQUIRED)

# 打印 OpenCV 相关信息
message("OpenCV Version: ${OpenCV_VERSION}")
message("OpenCV Include Dirs: ${OpenCV_INCLUDE_DIRS}")
message("OpenCV Libraries: ${OpenCV_LIBS}")

# 打印项目路径信息
message("---------------------------------------------------")
message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}")

# 包含头文件路径
include_directories(
    ${PROJECT_SOURCE_DIR}
    ${OpenCV_INCLUDE_DIRS}
)

# 设置可执行文件的输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build)

# 添加第一个可执行文件
add_executable(test_init main.cc include/stereo_camera_parameter.h)
target_link_libraries(test_init ${OpenCV_LIBS} -Wl,--no-as-needed)

# 添加第二个可执行文件
add_executable(test_load main_load_para.cc include/stereo_camera_parameter.h)
target_link_libraries(test_load ${OpenCV_LIBS} -Wl,--no-as-needed)
